"""
Problem 62: https://projecteuler.net/problem=62

The cube, 41063625 (345^3), can be permuted to produce two other cubes:
56623104 (384^3) and 66430125 (405^3). In fact, 41063625 is the smallest cube
which has exactly three permutations of its digits which are also cube.

Find the smallest cube for which exactly five permutations of its digits are
cube.
"""

# _*_ conding:UTF-8 _*_
'''
@author = Kuperain
@email = kuperain@aliyun.com
@IDE = VSCODE Python3.8.3
@creat_time = 2022/5/19
'''


def solution(total: int = 5) -> tuple:
    CubesDict = {k: ''.join(sorted(list(str(k**3)), reverse=True))
                 for k in range(10000)}
    # print(CubesDict)
    CubesDict_rev = dict()
    for key, val in CubesDict.items():
        if val in CubesDict_rev:
            CubesDict_rev[val] = CubesDict_rev[val] + [key]
        else:
            CubesDict_rev[val] = [key]
    # print(CubesDict_rev)

    res = [(key, val)
           for key, val in CubesDict_rev.items() if len(val) == total]
    print(res)
    return min([item[1][0] for item in res])


if __name__ == "__main__":
    import doctest
    doctest.testmod(verbose=False)

    print(solution())
    # 5027 
    # [('987655433210', [5027, 7061, 7202, 8288, 8384]),
    #  ('987665433210', [5196, 8124, 8496, 9702, 9783])]
